import React, {PropTypes} from 'react';
import {Group, Field, Button} from 'amazeui-touch';
import {connect} from 'react-redux';
import Action from '../store/actions';
import {bindActionCreators} from 'redux';

@connect(
    state => ({...state}),
    dispatch => bindActionCreators(Action, dispatch)
)
export default class Login extends React.Component {
    handleSubmit(e) {
        e.preventDefault();
        let userName = this.refs.userName.getValue();
        let password = this.refs.password.getValue();
        this.props.signin(userName, password);
    }

    render() {
        return (
            <div>
                <Group
                >
                    <div className="login">登录页面</div>
                    <div className="form-set">
                        <Field ref="userName" placeholder="账号"/>
                        <Field ref="password" placeholder="密码"/>
                    </div>
                    <Field
                        value="提交"
                        type="submit"
                        amStyle="primary"
                        block
                        onClick={this.handleSubmit.bind(this)}
                    />
                    <div className="msg">{this.props.auth.message.failMsg}</div>
                </Group>
            </div>
        );
    }
}
